package com.mz.mattress.client.service.impl;

import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
import com.mz.mattress.api.entity.WxRefundRecord;
import com.mz.mattress.client.mapper.WxRefundRecordMapper;
import com.mz.mattress.client.service.WxRefundRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

@Service
public class WxRefundRecordServiceImpl implements WxRefundRecordService {

    @Autowired
    private WxRefundRecordMapper wxRefundRecordMapper;

    @Override
    public void insert(WxPayRefundResult result) {

        if (result == null) {
            return;
        }

        WxRefundRecord record = new WxRefundRecord();
        record.setAppId(result.getAppid());
        record.setMchId(result.getMchId());
        record.setResultCode(result.getResultCode());
        record.setResultMsg(result.getReturnMsg());
        record.setRefundId(result.getRefundId());
        record.setNonceStr(result.getNonceStr());
        record.setTransactionId(result.getTransactionId());
        record.setOutTradeNo(result.getOutTradeNo());
        record.setOutRefundNo(result.getOutRefundNo());
        record.setSign(result.getSign());
        record.setTotalFee(result.getTotalFee());
        record.setRefundFee(result.getRefundFee());
        record.setCashRefundFee(result.getCashRefundFee());

        wxRefundRecordMapper.insert(record);
    }

    @Override
    public List<WxRefundRecord> selectByOrderId(Serializable orderId) {
        return null;
    }
}
